<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="B2B电商平台" name="description" />
<meta content="B2B电商平台" name="keyword" />

<title>B2B电商平台.用户分销</title>
<link rel="icon" href="include/images/icss.ico" type="image/x-icon" />
<link rel="shortcut icon" href="include/images/icss.ico"
	type="image/x-icon" />
<link rel="stylesheet" type="text/css"
	href="<%=path %>/include/css/global.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path %>/include/css/style.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path %>/include/css/pro.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path %>/include/css/proManage.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path %>/include/css/mmt_trading.css" />

<link rel="stylesheet"
	href="<%=path %>/include/JQuery ui/css/smoothness/jquery-ui-1.7.3.custom.css"
	type="text/css"></link>
<link rel="stylesheet" type="text/css"
	href="<%=path%>/include/pagination/page.css" media="all">
<script type="text/javascript"
	src="<%=path %>/include/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="<%=path %>/include/js/cookies.js"></script>
<script type="text/javascript" src="<%=path %>/include/js/icss.busin.js"></script>
<script type="text/javascript"
	src="<%=path %>/include/JQuery ui/js/jquery-ui-1.7.3.custom.min.js"></script>
<script type="text/javascript"
	src="<%=path %>/include/js/icss.common.js"></script>
<script type="text/javascript"
	src="<%=path%>/include/pagination/jquery.pagination.js"></script>
<script type="text/javascript"
	src="<%=path%>/include/pagination/init.js"></script>
<script type="text/javascript" src="<%=path%>/include/layer/layer.js"></script>
<link href="<%=path %>/include/DatePicker/skin/WdatePicker.css"
	rel="stylesheet" type="text/css">
<script src="<%=path %>/include/DatePicker/WdatePicker.js"
	charset="UTF-8" type="text/javascript"></script>
<style type="text/css">
.price a.price_rise {
	background-position: -62px -126px;
}

.price a.price_drop {
	background-position: -62px -86px;
}

.price a.price_null {
	background-position: -1px -280px;
	padding-right: 0px;
}

.expire a.expire_drops {
	background-position: -61px -93px;
}

.expire a.expire_rise {
	background-position: -61px -134px;
}

.expire a.expire_null {
	background-position: -61px -15px;
	padding-right: 0px;
}

thead th {
	border: 1px solid #ddd;
	font-weight: bold;
}

#userShareList a {
	text-decoration: none;
}

#userShareList td {
	padding: 4px 4px;
	border: 1px solid #ddd;
}

#lie th {
	border: 1px solid #ddd;
}

.search_lis_se input {
	height: 24px;
}

.save {
	width: 44px;
	height: 24px;
	line-height: 24px;
	background-color: transparent;
	background-repeat: no-repeat;
	background-position: 0 -203px;
	border: 0;
	cursor: pointer;
	font: 12px/1.5 arial, tahoma, \5b8b\4f53;
	margin: 0 0 0 5px;
	outline: none;
	background-image: url('<%=path%>/include/css/img/xs_bgx.png');
}

button {
	width: 44px;
	height: 24px;
	line-height: 24px;
	background-color: transparent;
	background-repeat: no-repeat;
	background-position: 0 -203px;
	border: 0;
	cursor: pointer;
	font: 12px/1.5 arial, tahoma, \5b8b\4f53;
	margin: 0 0 0 5px;
	outline: none;
	background-image: url('<%=path%>/include/css/img/xs_bgx.png');
}

th {
	text-align: center;
	vertical-align: middle
}
</style>

<script type="text/javascript">
	$(document).ready(function() {
		_queryList();
	});
	
	//全选
    function selectAlledTop(){
    	if($("#topCheckAll").attr("checked")=="checked"){
		    $("input[name='uuid']").each(function(index,item){
	    	 	 if($(this).is(':disabled')){
                     $(this).prop('checked',false);
                 }else{
                 	  $(this).attr("checked",true);
                 }
		    })
    	}else{
		    $("input[name='uuid']").each(function(index,item){
		    	 if($(this).is(':disabled')){
                     $(this).prop('checked',false);
                 }else{
                 	  $(this).attr("checked",false);
                 }
		    })
    	}
    }
    
    var pagination;
    //查询审核列表
	function _queryList(){
		var userName = $("#queryUserName").val();
		var frmStartTime = $("#frmStartTime").val();
	    var frmEndTime = $("#frmEndTime").val();
	    if(frmStartTime>frmEndTime){
		    if(frmEndTime !=null&&frmEndTime !=""&&frmEndTime !="undefined"){
		    	parent.swal("开始时间不可以大于结束时间!");
		    	return;
		    }
		}  
		var status = $("#status").val(); 
		var url = "<%=path %>/userShare/getUserSharePage.do?userName="+userName+"&frmStartTime="+frmStartTime+"&frmEndTime="+frmEndTime+"&status="+status;
  		pagination = _initPagination({'pageId':'pagination', 'cKey':'','url': url, 'rows': 10, 'callback':_initDataList});
  		
	}
	function _initDataList(data) {
	 		var d = data.rows;
	 		var total = data.total;
			var str = "";
			$("#userShareList").empty();
			for(var i=0;i<d.length;i++){
				str += "<tr>";
				str += "    <td class='t1' style='text-align:center;vertical-align: middle'>";
			 	str += " 		<input type='checkbox' name='uuid' value='"+d[i].uuid+"' star='3' mainpro=''>";
				str += "    </td>";
				str += "    <td class='t3' style='text-align:center;vertical-align: middle'>"+d[i].userName;
				str += "	</td>";
				str +="		<td class='t3' style='text-align:right;vertical-align: middle'>"+d[i].userCode;
				str +="		</td>";
				
				if(d[i].status=='1'){
					str +="		<td class='t2' id='pubdateTd'  style='text-align:center;vertical-align: middle'>审核通过</td>";
				}else if(d[i].status=='2'){
					str +="		<td class='t2' id='pubdateTd'  style='text-align:center;vertical-align: middle'>审核不通过</td>";
				} else {
					str +="		<td class='t2' id='pubdateTd'  style='text-align:center;vertical-align: middle'>待审核</td>";
				}
				str +="		<td class='t4' id='pubdateTd'  style='text-align:center;vertical-align: middle'>"+d[i].createTime;
				str +=" 	</td>";
				str +="		<td class='t2' id='pubdateTd'  style='text-align:center;vertical-align: middle'>";
				if(d[i].status=='2'){ 
					str +="	<a href='javascript:_audit(\""+ d[i].uuid +"\",\"1\",\"noBatch\")' >通过</a> &nbsp;&nbsp;"
				} else if (d[i].status=='1') {
					str +="	<a href='javascript:_audit(\""+ d[i].uuid +"\",\"2\",\"noBatch\")' >拒绝</a>&nbsp;&nbsp;"
				}else {
					str +="	<a href='javascript:_audit(\""+ d[i].uuid +"\",\"1\",\"noBatch\")' >通过</a> &nbsp;&nbsp; <a href='javascript:_audit(\""+ d[i].uuid +"\",\"2\",\"noBatch\")' >拒绝</a>&nbsp;&nbsp;"
				}
				str +=" <a href='javascript:toStatistics(\""+ d[i].userCode +"\")' >详情</a></td>";
				str +=" </tr>";
			}
			$("#userShareList").append(str);
			setTimeout(function(){_reHeight("rightFrame","contentDiv");},1000);
			
	 }
	 //批量审核
	 function auditAbove(status){
	    var uuids =""
    	 $("input[name='uuid']").each(function(index,item){
    		 if($(this).attr("checked")=="checked"){
    			 uuids += $(this).val()+",";
        	 }
	    })
	    if(uuids==""){
		   parent.layer.alert("请至少选择一条记录!");
		    return;
		}else{
			_audit(uuids,status,'batch');
		 }
	 }
	 //进入统计详情页面
	 function toStatistics(userCode) {
		 window.location.href ="<%=path%>/userShare/toUserShareStatisticsPage.do?userCode=" + userCode;
	 }
	//进入审核页面
	function _audit(uuid,status,ifBatch){
		var url = "<%=path%>/userShare/toAuditDetail.do";
		var title = "";
		if(ifBatch == 'batch'){		//批量审核
			title = '批量审核操作';
		}else if(ifBatch == 'noBatch'){//单个商品审核
			title = '审核操作';
		}
		// 审核通过 
		if (status == '1') {
			_auditIfBatch(uuid, '',status,ifBatch);
		}
		// 审核不通过，弹框
		if (status == '2') {
			parent.layer.open({
				title:title,
				type: 2,
				fixed: false, //不固定
				offset: '100px',
				area: ['460px', '290px'],
				shadeClose: false, //点击遮罩关闭
				content: url,
				btn: ['确定', '取消'],
				yes: function(index, layero){
					//按钮【按钮一】的回调
					var body = layer.getChildFrame('body', index);
					//var iframeWin = window[layero.find('iframe')[0]['name']];   //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
					var iframeWin = $(layero).find("iframe")[0].contentWindow;
					//iframeWin.setValues();
					var flag = iframeWin._checkReason();//验证审核不通过时，是否填写不通过原因
					if(flag){
						var applyShareDesc = iframeWin.getApplyShareDesc();//$("#applyShareDesc").val();
						_auditIfBatch(uuid, applyShareDesc,status, ifBatch);
					}
					
				},
				btn2: function(index, layero){
					//按钮【按钮二】的回调
					//return false 开启该代码可禁止点击该按钮关闭
				},
				maxmin:true
			});
		}
		
	}
	//审核操作
	function _auditIfBatch(uuid, applyShareDesc,status, ifBatch){
		$.ajax({
	 		type:"GET",
			url:"<%=path%>/userShare/auditUserShare.do",
			data : {
				uuid : uuid,
				applyShareDesc : applyShareDesc,
				status : status,
				ifBatch : ifBatch
			},
			dataType : "json",
			async : false, //同步执行
			success : function(data) {
				if (data.success) {
					if (ifBatch == 'batch') {
						parent.swal("批量审核成功!", "", "success");
					} else if (ifBatch == 'noBatch') {
						parent.swal("审核成功!", "", "success");
					}
					$("#topCheckAll").attr("checked", false);
					_queryList();
					setTimeout(parent.layer.closeAll(), 3000);
				} else {
					if (ifBatch == 'batch') {
						parent.swal("OMG", "批量审核失败！", "error");
					} else if (ifBatch == 'noBatch') {
						parent.swal("OMG", "审核失败！", "error");
					}
					$("#topCheckAll").attr("checked", false);
				}
			},
			error : function(data) {
			}
		});
	}
</script>
</head>
<body>
	<div id="contentDiv"
		style="padding: 4px; width: 99%; font-family: '微软雅黑';">
		<input type="hidden" id="refundType" name="refundType" /> <input
			type="hidden" id="rejectReason" name="rejectReason" />
		<div class="colnums-2-ab-b" style="overflow-x: auto;">
			<div class="toptil">审核用户分销</div>
			<div class="search_lis"
				style="border: 1px solid #e0e0e0; background: #f5f5f5; padding-left: 10px; margin-bottom: 10px; width: 98.5%; height: 30px;">
				<div class="search_lis_se" style="font-size: 14px;">
					<span>用户名:</span> <input name="queryUserName" id="queryUserName"
						type="text" class="in_bit" maxlength="40" value=""
						placeholder="请输入用户名称 ..." style="color: #000000; width: 120px;">
					<span style="margin-left: 5px;">申请时间: </span> <input type="text"
						id="frmStartTime" name="frmStartTime"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,maxDate:'#F{$dp.$D(\'frmEndTime\')}'})"
						style="width: 110px; height: 24px; padding-left: 3px"
						onfocus="WdatePicker({position:{left:315,top:88}})" class="Wdate"
						value="" realvalue=""> <span style="margin-left: 5px;">至</span>
					<input type="text" id="frmEndTime" name="frmEndTime"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,minDate:'#F{$dp.$D(\'frmStartTime\')}'})"
						style="width: 110px; height: 24px; padding-left: 3px; margin-right: 2px;"
						onfocus="WdatePicker({position:{left:464,top:88}})" class="Wdate"
						value="" realvalue=""> <span style="margin-left: 5px;">审核状态:</span>
					<select id="status" name="status"
						style="color: #000000; width: 94px; height: 24px;"
						autocomplete="off">
						<option value="" selected>全部</option>
						<option value="0">待审核</option>
						<option value="1">审核通过</option>
						<option value="2">审核不通过</option>
					</select>
					<button type="button" class="save" onclick="_queryList()">查询</button>
					<button type="button"
						style="width:66px;height:24px;background-size: 180px 458px;"
						onclick="javascript:auditAbove('1')">批量通过</button>
					<button type="button"
						style="width:66px;height:24px;background-size: 180px 458px;"
						onclick="javascript:auditAbove('2')">批量不通过</button>
				</div>
				<div class="wantBuy" id="caigouInfo"></div>
			</div>
			<div class="listed_tb_k" style="width: 99.65%; border: none;">
				<table cellspacing="0" cellpadding="0">
					<thead>
						<tr id="lie">
							<th class="t1"><input id="topCheckAll" name="topCheckAll"
								type="checkbox" onclick="selectAlledTop()" class="chk"></th>
							<th class="t3">用户名名称</th>
							<th class="t3">用户ID</th>
							<th class="t2">审核状态</th>
							<th class="t4">申请日期</th>
							<th class="t3">操作</th>
						</tr>
					</thead>
					<tbody id="userShareList">
					</tbody>
				</table>
				<div id="pagination"></div>
			</div>
		</div>
		<div class="clear"></div>
	</div>
</body>
<script type="text/javascript">
	$(document).ready(function() {
		_reHeight("rightFrame", "contentDiv");
	});
</script>
</html>
